﻿//编辑网站基本信息
EditSiteInfo = function () {
    var EditSiteInfoForm = Ext.create("Ext.form.Panel", {
        width: 360,
        height: 560,
        autoScroll: true,
        layout: "anchor",
        defaultType: "textfield",
        labelWidth: 35,
        baseCls: "x-plain",
        defaults: { labelAlign: 'right', msgTarget: "side" },
        buttonAlign: "center",
        items: [{
            name: "Name",
            fieldLabel: "<font color='red'>*</font>网站名",
            allowBlank: false,
            blankText: "编号不能为空",
            regex: /^[\S]{1,20}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "Title",
            fieldLabel: "<font color='red'>*</font>网站标题",
            allowBlank: false,
            width:400,
            blankText: "标题不能为空"
        }, {
            name: "Url",
            fieldLabel: "<font color='red'>*</font>网址",
            allowBlank: false,
            blankText: "网址不能为空",
            regex: /^[\S]{1,150}$/,
            regexText: "请填写1～150个字符"
        }, {
            name: "ChannelUrl",
            fieldLabel: "频道网址规则",
            blankText: "网址不能为空",
            regex: /^[\S]{1,150}$/,
            regexText: "请填写1～150个字符"
        }, {
            name: "ArticleUrl",
            fieldLabel: "内容网址规则",
            blankText: "网址不能为空",
            regex: /^[\S]{1,150}$/,
            regexText: "请填写1～150个字符"
        }, {
            name: "Dir",
            fieldLabel: "安装路径",
            regexText: "主网站下某个目录，独立网站这为空"
        }, {
            name: "Keywords",
            fieldLabel: "关键字",
            xtype: 'textareafield',
            regexText: "请填写0～120个字符"
        }, {
            name: "Description",
            fieldLabel: "网站简介",
            xtype: 'textareafield',
            regexText: "请填写0～260个字符"
        }, {
            name: "IsHtml",
            fieldLabel: "是否静态",
            xtype: "combo",
            //传入后台真实值value field /value
            editable: false,
            value: 2,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
                      { "show": "部分静态", "value": 2 },
			        { "show": "静态", "value": 1 },
			        { "show": "动态", "value": 0 }
			    ]
            }),
            queryMode: 'local',
            displayField: 'show',
            valueField: 'value'
        }, {
            name: "IsCacheTemplate",
            fieldLabel: "模板是否缓存",
            xtype: "combo",
            //传入后台真实值value field /value
            editable: false,
            value: 2,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
                      { "show": "缓存", "value": true },
			        { "show": "不缓存", "value": false }
			    ]
            }),
            queryMode: 'local',
            displayField: 'show',
            valueField: 'value'
        }, {
            name: "CacheSecond",
            xtype: "numberfield",
            value: 3600,
            fieldLabel: "<font color='red'>*</font>默认缓存时间",
            allowBlank: false
        }, {
            name: "IsZhanQun",
            fieldLabel: "是否站群",
            xtype: "combo",
            //传入后台真实值value field /value
            editable: false,
            value: 2,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
                      { "show": "是", "value": true },
			        { "show": "否", "value": false }
			    ]
            }),
            queryMode: 'local',
            displayField: 'show',
            valueField: 'value'
        }, {
            name: "PagingNum",
            xtype: "numberfield",
            value: 8000,
            fieldLabel: "<font color='red'>*</font>文章内容分页字数",
            allowBlank: false
        }, {
            name: "MaxPageNum",
            xtype: "numberfield",
            value: 0,
            fieldLabel: "<font color='red'>*</font>展示文章总页数",
            allowBlank: false
        }, {
            name: "Token",
            fieldLabel: "微信Token",
            allowBlank: true
        }, {
            name: "ICP",
            fieldLabel: "备案号",
            regex: /^[\S]{0,40}$/,
            regexText: "请填写0～40个字符"
        }, {
            name: "CountJs",
            width: 600,
            heigth:200,
            xtype: 'textareafield',
            fieldLabel: "统计Js"
        }
			],
        listeners: {
            "show": function () {
                if (id && id != "") {
                    //加载表单数据
                    EditSiteInfoForm.form.load(
                                {
                                    url: "/manager/SiteInfo/Look/",
                                    method: "get",
                                    success: function (form, action) {

                                    },
                                    failure: function (form, action) {
                                        Ext.Msg.alert("提示信息", "对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
                }
            }
        },
        dockedItems: [{
            xtype: 'toolbar',
            dock: 'bottom',
            ui: 'footer',
            bodyStyle: "padding:20px;",
            items: [{
                iconCls: 'icon-save',
                text: "保存信息",
                minWidth: 70,
                handler: function () {
                    //alert(EditSiteInfoForm.getForm().isValid())
                    if (EditSiteInfoForm.getForm().isValid()) {
                        //弹出效果 Ext.MessageBox.alert("asdf");
                        Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                        setTimeout(function () { }, 1000);
                        EditSiteInfoForm.form.submit({
                            url: "/manager/SiteInfo/Update/",
                            method: "POST",
                            success: function (form, action) {
                                //成功后
                                Ext.MessageBox.hide();
                                var flag = action.result.success;
                                if (flag == "true") {
                                   
                                   Ext.helper.msg("恭喜", "修改成功!");
                                   
                                }
                                else {
                                    var message = action.result.message;
                                    if (message) {
                                        Ext.MessageBox.alert("修改失败!", message);
                                    }
                                    else {
                                        Ext.MessageBox.alert("提示!", "修改失败!");
                                     
                                    }

                                }
                            },
                            failure: function (form, action) {
                                Ext.MessageBox.alert("提示!", "修改失败!");
                               
                            }
                        });
                    }
                }
            }, {
                iconCls: 'icon-reset',
                text: "重置",
                minWidth: 70,
                qtip: "重置数据",
                handler: function () {
                    //加载表单数据
                    EditSiteInfoForm.getForm().reset();
                    EditSiteInfoForm.form.load(
                                {
                                    url: "/manager/SiteInfo/Look/",
                                    method: "get",
                                    success: function (form, action) {
                                    },
                                    failure: function (form, action) {
                                        //Ext.Msg.alert("提示信息","对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
                }
            }, {
                iconCls: 'icon-reset',
                text: "取 消",
                minWidth: 70,
                handler: function () {
                    EditSiteInfoWin.hide();
                }

            }]
        }]

    });

    var main = Ext.create('Ext.container.Container', {
        padding: '20px;',
        height: 600,
        renderTo: "SiteInfoForm",
        layout: {
            type: 'vbox',
            align: 'stretch'
        },

        items: [EditSiteInfoForm]
    });
    EditSiteInfoForm.form.load(
                                {
                                    url: "/manager/SiteInfo/Look/",
                                    method: "get",
                                    success: function (form, action) {
                                    },
                                    failure: function (form, action) {
                                        //Ext.Msg.alert("提示信息","对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );


}
    EditSiteInfo();